home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / strlib12.zip / STRLIB.DOC < prev    next >
Text File  |  1991-01-21  |  13KB  |  486 lines

  1.  
  2.                  StrLib v1.2 (c) 1990, 1991 Serious Cybernetics
  3.                     Turbo Pascal(tm) 5.5 String Library Unit
  4.                                  by Scott Davis
  5.  
  6. -------------------------------------------------------------------------------
  7.  
  8. The following files should be included in STRLIB12.ZIP :
  9.  
  10. STRLIB.DOC      StrLib Documentation
  11. STRLIB.TPU      StrLib Unit
  12.  
  13. -------------------------------------------------------------------------------
  14.  
  15. STRLIB.TPU contains a library of string functions for use with Turbo
  16. Pascal (tm) 5.5
  17.  
  18. The following functions are defined in StrLib :
  19.  
  20. FUNCTION All(s : STRING; n : BYTE) : STRING;
  21. FUNCTION Center(s : STRING; n : BYTE) : STRING;
  22. FUNCTION CenterLoc(s : STRING; w : BYTE) : BYTE;
  23. FUNCTION Clip(s : STRING) : STRING;
  24. FUNCTION FullClip(s : STRING) : STRING;
  25. FUNCTION GetFirst(s : STRING) : STRING;
  26. FUNCTION GetLast(s : STRING) : STRING;
  27. FUNCTION Hex(s : STRING) : BOOLEAN;
  28. FUNCTION HexStr(i : INTEGER) : STRING;
  29. FUNCTION HexVal(s : STRING) : INTEGER;
  30. FUNCTION Left(s : STRING) : STRING;
  31. FUNCTION LeftClip(s : STRING) : STRING;
  32. FUNCTION LeftPad(s : STRING; n : BYTE) : STRING;
  33. FUNCTION LeftStr(s : STRING; n : BYTE) : STRING;
  34. FUNCTION LowCase(s : CHAR) : CHAR;
  35. FUNCTION Lower(s : STRING) : STRING;
  36. FUNCTION MakeName(s1 : STRING; s2 : STRING; r : BOOLEAN) : STRING;
  37. FUNCTION Normal(s : STRING) : STRING;
  38. FUNCTION Numeric(s : STRING) : BOOLEAN;
  39. FUNCTION NumVal(s : STRING) : INTEGER;
  40. FUNCTION Right(s : STRING) : STRING;
  41. FUNCTION RightPad(s : STRING; n : BYTE) : STRING;
  42. FUNCTION RightStr(s : STRING; n : BYTE) : STRING;
  43. FUNCTION Spaces(n : BYTE) : STRING;
  44. FUNCTION NumStr(i : INTEGER) : STRING;
  45. FUNCTION Upper(s : STRING) : STRING;
  46. FUNCTION ZeroClip(s : STRING) : STRING;
  47. FUNCTION ZeroPad(s : STRING; n : BYTE) : STRING;
  48.  
  49. -------------------------------------------------------------------------------
  50.  
  51. FUNCTION All(s : STRING; n : BYTE) : STRING;
  52.  
  53.  
  54. "All" will return a string of "n" repetitions of "s".  Examples :
  55.  
  56.    WriteLn(All('*',7));
  57.  
  58. will display '*******'.
  59.  
  60.    WriteLn(All('[]',10));
  61.  
  62. will display '[][][][][][][][][][]'.
  63.  
  64. -------------------------------------------------------------------------------
  65.  
  66. FUNCTION Center(s : STRING; n : BYTE) : STRING;
  67.  
  68.  
  69. "Center" will return a "s" centered in a string of "n" length.  Leading and
  70. trailing spaces will be ignored.  Examples :
  71.  
  72.    WriteLn(Center('This',10));
  73.  
  74. will display '   This   '.
  75.  
  76.    WriteLn(Center('  This',10));
  77.  
  78. will display '   This   '.
  79.  
  80. -------------------------------------------------------------------------------
  81.  
  82. FUNCTION CenterLoc(s : STRING; w : BYTE) : BYTE;
  83.  
  84.  
  85. "CenterLoc" will return the position to display "s" on screen of "w" width.
  86. The entire length of "s" is considered (including leading and trailing spaces).
  87. Examples :
  88.  
  89.    XLoc := CenterLoc('Print',80);
  90.  
  91. will set XLoc equal to 38.
  92.  
  93.    XLoc := CenterLoc('Print    ',40);
  94.  
  95. will set XLoc equal to 16.
  96.  
  97. -------------------------------------------------------------------------------
  98.  
  99. FUNCTION Clip(s : STRING) : STRING;
  100.  
  101.  
  102. "Clip" will return a string of "s" with all trailing spaces removed.
  103. Examples :
  104.  
  105.    WriteLn('Well'+Clip('Hello    ')+'There');
  106.  
  107. will display 'WellHelloThere'.
  108.  
  109.    WriteLn('Well'+Clip('   Hello ')+'There');
  110.  
  111. will display 'Well   HelloThere'.
  112.  
  113. -------------------------------------------------------------------------------
  114.  
  115. FUNCTION FullClip(s : STRING) : STRING;
  116.  
  117.  
  118. "FullClip" will return a string of "s" with all leading and trailing spaces
  119. removed.  Examples :
  120.  
  121.    WriteLn('Well'+FullClip('Hello    ')+'There');
  122.  
  123. will display 'WellHelloThere'.
  124.  
  125.    WriteLn('Well'+FullClip('   Hello ')+'There');
  126.  
  127. will display 'WellHelloThere'.
  128.  
  129. -------------------------------------------------------------------------------
  130.  
  131. FUNCTION GetFirst(s : STRING) : STRING;
  132.  
  133.  
  134. "GetFirst" will return the first name of the full name "s".  Leading and
  135. trailing blanks are ignored.  Examples :
  136.  
  137.    WriteLn(GetFirst('Gilbert N. Bates'));
  138.  
  139. will display 'Gilbert'.
  140.  
  141.    WriteLn(GetFirst('  Steve   "Evil Twin"   Pogo   '));
  142.  
  143. will display 'Steve'.
  144.  
  145. -------------------------------------------------------------------------------
  146.  
  147. FUNCTION GetLast(s : STRING) : STRING;
  148.  
  149.  
  150. "GetLast" will return the last name of the full name "s".  Leading and
  151. trailing blanks are ignored.  Examples :
  152.  
  153.    WriteLn(GetLast('Gilbert N. Bates'));
  154.  
  155. will display 'Bates'.
  156.  
  157.    WriteLn(GetLast('  Steve   "Evil Twin"   Pogo   '));
  158.  
  159. will display 'Pogo'.
  160.  
  161. -------------------------------------------------------------------------------
  162.  
  163. FUNCTION Hex(s : STRING) : BOOLEAN;
  164.  
  165.  
  166. "Hex" will return true if "s" is a valid hexadecimal number.  Leading and
  167. trailing blanks are ignored.  Example :
  168.  
  169.   HexTest := FALSE;
  170.   WHILE HexTest = FALSE DO BEGIN
  171.      WriteLn('Enter a hex value : ');
  172.      ReadLn(HexEntry);
  173.      HexTest := Hex(HexEntry);
  174.   END;
  175.  
  176. will prompt until a valid hex string is entered.
  177.  
  178. -------------------------------------------------------------------------------
  179.  
  180. FUNCTION HexStr(i : INTEGER) : STRING;
  181.  
  182.  
  183. "HexStr" will return a string containing a hexadecimal representation of "i".
  184. Examples :
  185.  
  186.    WriteLn(HexStr(191));
  187.  
  188. will display 'BF'.
  189.  
  190.    WriteLn(HexStr(32767));
  191.  
  192. will display '7FFF'.
  193.  
  194. -------------------------------------------------------------------------------
  195.  
  196. FUNCTION HexVal(s : STRING) : INTEGER;
  197.  
  198.  
  199. "HexVal" will return the numeric value of the hex string "s".  Examples :
  200.  
  201.     TestVal := HexVal('1b');
  202.  
  203. will set TestVal equal to 27.
  204.  
  205.     TestVal := HexVal('d') + 2;
  206.  
  207. will set TestVal equal to 15.
  208.  
  209. -------------------------------------------------------------------------------
  210.  
  211. FUNCTION Left(s : STRING) : STRING;
  212.  
  213.  
  214. "Left" will return a string "s" left justified within the length of "s".
  215. Example :
  216.  
  217.    WriteLn(Left('   Hello   ')+'There');
  218.  
  219. will display 'Hello      There'.
  220.  
  221. -------------------------------------------------------------------------------
  222.  
  223. FUNCTION LeftClip(s : STRING) : STRING;
  224.  
  225. "LeftClip" will return a string of "s" with all leading spaces removed.
  226. Examples :
  227.  
  228.    WriteLn('Well'+LeftClip('Hello    ')+'There');
  229.  
  230. will display 'WellHello    There'.
  231.  
  232.    WriteLn('Well'+LeftClip('   Hello ')+'There');
  233.  
  234. will display 'WellHello There'.
  235.  
  236. -------------------------------------------------------------------------------
  237.  
  238. FUNCTION LeftPad(s : STRING; n : BYTE) : STRING;
  239.  
  240.  
  241. "LeftPad" will pad string s with leading spaces to a length of "n".
  242. Example :
  243.  
  244.    WriteLn(LeftPad('Hello',10)+'There');
  245.  
  246. will display '     HelloThere'.
  247.  
  248. -------------------------------------------------------------------------------
  249.  
  250. FUNCTION LeftStr(s : STRING; n : BYTE) : STRING;
  251.  
  252.  
  253. "LeftStr" will return the left "n" characters of string "s".  Example :
  254.  
  255.    WriteLn(LeftStr('ABCDEFG',3));
  256.  
  257. will display 'ABC'.
  258.  
  259. -------------------------------------------------------------------------------
  260.  
  261. FUNCTION LowCase(s : CHAR) : CHAR;
  262.  
  263.  
  264. "LowCase" will return character "s" forced to lower case.  This function is
  265. the opposite of the Turbo Pascal function UpCase.  Examples :
  266.  
  267.    WriteLn(LowCase('H'));
  268.  
  269. will display 'h'.
  270.  
  271.    WriteLn(LowCase('j'));
  272.  
  273. will display 'j'.
  274.  
  275. -------------------------------------------------------------------------------
  276.  
  277. FUNCTION Lower(s : STRING) : STRING;
  278.  
  279.  
  280. "Lower" will return string "s" forced to lower case.  Example :
  281.  
  282.    WriteLn(Lower('This is an EXAMPLE of using Lower');
  283.  
  284. will display 'this is an example of using lower'.
  285.  
  286. -------------------------------------------------------------------------------
  287.  
  288. FUNCTION MakeName(s1 : STRING; s2 : STRING; r : BOOLEAN) : STRING;
  289.  
  290.  
  291. "MakeName" will return a full name composed of first name "s1" and last
  292. name "s2".  If "r" is true, "MakeName" will return the string in reverse
  293. order (last name first, divided by a comma).  Leading and trailing blanks
  294. are ignored.  Examples :
  295.  
  296.    WriteLn(MakeName('  Steve  ','  Pogo   ',FALSE));
  297.  
  298. will display 'Steve Pogo'.
  299.  
  300.    WriteLn(MakeName('  Gilbert   ','    Bates  ',TRUE));
  301.  
  302. will display 'Bates, Gilbert'.
  303.  
  304. -------------------------------------------------------------------------------
  305.  
  306. FUNCTION Normal(s : STRING) : STRING;
  307.  
  308.  
  309. "Normal" will return a normalized (first letter of each word is upper and all
  310. others are lower) string of "s".  Example :
  311.  
  312.    WriteLn(Normal('THIS IS YOUR LAST CHANCE');
  313.  
  314. will display 'This Is Your Last Chance');
  315.  
  316. -------------------------------------------------------------------------------
  317.  
  318. FUNCTION Numeric(s : STRING) : BOOLEAN;
  319.  
  320. "Numeric" will return true if "s" contains a valid numeric value.  Leading
  321. and trailing blanks are ignored.  Example :
  322.  
  323.    IF NOT Numeric(EntryStr) THEN WriteLn('Not Numeric');
  324.  
  325. will display 'Not Numeric' if the string EntryStr is not a valid numeric.
  326.  
  327. -------------------------------------------------------------------------------
  328.  
  329. FUNCTION NumVal(s : STRING) : INTEGER;
  330.  
  331. "NumVal" will return the integer value of numeric string "s".  Leading and
  332. trailing blanks are ignored.  Examples :
  333.  
  334.    TestVal := NumVal('  32 ');
  335.  
  336. will set TestVal equal to 32.
  337.  
  338.    TestVal := NumVal('4')+4;
  339.  
  340. will set TestVal equal to 8.
  341.  
  342.    TestVal := NumVal('9j');
  343.  
  344. will set TestVal equal to 0.
  345.  
  346. -------------------------------------------------------------------------------
  347.  
  348. FUNCTION Right(s : STRING) : STRING;
  349.  
  350.  
  351. "Right" will return a string "s" right justified within the length of "s".
  352. Example :
  353.  
  354.    WriteLn(Left('   Hello   ')+'There');
  355.  
  356. will display '      HelloThere'.
  357.  
  358. -------------------------------------------------------------------------------
  359.  
  360. FUNCTION RightPad(s : STRING; n : BYTE) : STRING;
  361.  
  362.  
  363. "RightPad" will pad string "s" with trailing spaces to a length of "n".
  364. Example :
  365.  
  366.    WriteLn(LeftPad('Hello',10)+'There');
  367.  
  368. will display 'Hello     There'.
  369.  
  370. -------------------------------------------------------------------------------
  371.  
  372. FUNCTION RightStr(s : STRING; n : BYTE) : STRING;
  373.  
  374.  
  375. "RightStr" will return the right "n" characters of string "s".  Example :
  376.  
  377.    WriteLn(RightStr('ABCDEFG',3));
  378.  
  379. will display 'EFG'.
  380.  
  381. -------------------------------------------------------------------------------
  382.  
  383. FUNCTION Spaces(n : BYTE) : STRING;
  384.  
  385.  
  386. "Spaces" will return a string of "n" spaces.  Example :
  387.  
  388.    WriteLn('Hello'+Spaces(5)+'There');
  389.  
  390. will display 'Hello     There'.
  391.  
  392. -------------------------------------------------------------------------------
  393.  
  394. FUNCTION NumStr(i : INTEGER) : STRING;
  395.  
  396.  
  397. "NumStr" will return a string containg "i".  Example :
  398.  
  399.    WriteLn('The answer is '+NumStr(42)+'.');
  400.  
  401. will display 'The answer is 42.'.
  402.  
  403. -------------------------------------------------------------------------------
  404.  
  405. FUNCTION Upper(s : STRING) : STRING;
  406.  
  407.  
  408. "Upper" will return string "s" forced to upper case.  Example :
  409.  
  410.    WriteLn(Upper('This is an EXAMPLE of using Upper');
  411.  
  412. will display 'THIS IS AN EXAMPLE OF USING UPPER'.
  413.  
  414. -------------------------------------------------------------------------------
  415.  
  416. FUNCTION ZeroClip(s : STRING) : STRING;
  417.  
  418.  
  419. "ZeroClip" will return string "s" with leading zeros removed.  Examples :
  420.  
  421.    WriteLn(ZeroClip('00000099'));
  422.  
  423. will display '99'.
  424.  
  425.    WriteLn(ZeroClip('01008'));
  426.  
  427. will display '1008'.
  428.  
  429.    WriteLn(ZeroClip('000'));
  430.  
  431. will display '0'.
  432.  
  433. -------------------------------------------------------------------------------
  434.  
  435. FUNCTION ZeroPad(s : STRING; n : BYTE) : STRING;
  436.  
  437.  
  438. "ZeroPad" will return string "s" padded with leading zeros to length "n".
  439. Examples :
  440.  
  441.    WriteLn(ZeroPad('14',9));
  442.  
  443. will display '000000014'.
  444.  
  445.    WriteLn(ZeroPad('009',4));
  446.  
  447. will display '0009'.
  448.  
  449. -------------------------------------------------------------------------------
  450.  
  451. StrLib is shareware. You may copy and distribute STRLIB12.ZIP freely, as well
  452. as use it for development of programs for your own use, to give away or to
  453. sell.  All I ask is that you include all of the original files, unmodified,
  454. and that you do not charge for the distribution of StrLib itself.
  455.  
  456. If you like StrLib and use it, any donation would be greatly appreciated
  457. ($10 suggested). This would help to encourage future enhancements to this
  458. unit and the writing of others like it.
  459.  
  460.  
  461. Questions, comments, and suggestions are welcome.
  462.  
  463. Send E/Mail to   Scott Davis
  464.                  Phoenix Starfighter BBS (2400 bps)
  465.                  Phone (404) 869-3410
  466.                  FidoNet Node 1:3616/20
  467.  
  468. Send US Mail to  Scott Davis
  469.                  Rt. 2 Box 95
  470.                  County Line Drive
  471.                  Lula, GA 30554
  472.  
  473. -------------------------------------------------------------------------------
  474.  
  475. I'd like to thank Danny Sosebee (Sysop of Phoenix Starfighter) for
  476. allowing me to use his BBS as a way to receive suggestions and comments
  477. regarding StrLib.  Also, I'd like to thank Ed Ivey (Sysop of Ed's Place
  478. BBS - 404/532-1978 - FidoNet Node 1:3616/1) for his continued support
  479. and assistance in distributing my little software "projects".
  480.  
  481. ------------------------------------------------------------------------------
  482.  
  483. StrLib (c) 1990, 1991 Serious Cybernetics
  484. Turbo Pascal (c) 1983, 1989 Borland International
  485.  
  486.